<!-- Phan khai bao bien cuc bo-->
<?php
$arr_status = array(1 => array("id" => -1, "name" => CONST_QA_STATUS_ALL_LABEL),
					2 => array("id" =>  0, "name" => CONST_QA_UNANSWER_STATUS_LABEL),
					3 => array("id" =>  1, "name" => CONST_QA_WAITING_STATUS_LABEL),
					4 => array("id" =>  2, "name" => CONST_QA_APPROVED_STATUS_LABEL),
					);
//Luu trang thai hien thoi
$v_status = -1;
if(isset($_REQUEST['hdn_status'])){	
	$v_status = $_REQUEST['hdn_status'];
}

//Luu ten cua linh vuc
$v_cate = "";
if(isset($_REQUEST['hdn_cate'])){
	$v_cate = $_REQUEST['hdn_cate'];
} 

$v_cate_id = 0;
if(isset($_REQUEST['hdn_cate_id'])){
	$v_cate_id = intval($_REQUEST['hdn_cate_id']);
}
// Luu ma co quan hanh chinh
$v_agency_id = 0;
if(isset($_REQUEST['hdn_agency_id'])){
	$v_agency_id = intval($_REQUEST['hdn_agency_id']);
}
// Luu ten co quan hanh chinh
$v_agency = "";
if(isset($_REQUEST['hdn_agency'])){
	$v_agency = $_REQUEST['hdn_agency'];
}
// Luu dieu kien loc hien thoi
$v_filter = "";
if(isset($_REQUEST['hdn_filter'])){
	$v_filter = _replace_bad_char($_REQUEST['hdn_filter']);
} 
$v_current_style_name = "odd_row";
$v_next_style_name = "round_row";
$v_count = sizeof($arr_all_onegate_qa);
// Tong so tat ca cac cau hoi
//$v_total_qa_count = sizeof($arr_all_onegate_qa_for_count);
// Tong so trang 
$v_total_page = ceil($v_total_qa/$v_number_qa_question_per_page);
/*
if ($v_count > 0) {
	$v_top_id  =   $arr_all_onegate_qa[0]['0'];
	$v_bottom_id = $arr_all_onegate_qa[$v_count-1]['0'];
} else {
	$v_top_id  =   0;
	$v_bottom_id = 0;
}
*/
$v_goto_url = "index.php";
// Luu ten style tiep theo
$v_current_item_id = '';
if(isset($_REQUEST['hdn_current_item_id'])){
	$v_current_item_id = $_REQUEST['hdn_current_item_id'];
}

?>
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0">
	<tr class="normal_title">
		<td><?php echo CONST_QA_QUESTION_LIST_TITLE;?>
			<a id="goto" href="" style=".color:white">#</a>
		</td>
	</tr>
</table>
<!-- bang chua cac tieu thuc loc-->
<table cellpadding="0" cellspacing="0" width="100%" border="0">
	<col width="15%"><col width="30%"><col width="20%"><col width="35%">
	<!--form chinh-->
		<form action="index.php" name="f_dsp_all_qa_question" method="post">
		<input type="hidden" name="fuseaction" value="DISPLAY_ALL_QA_QUESTION">
		<input type="hidden" name="hdn_filter" value="<?php echo $v_filter; ?>">
		<input type="hidden" name="hdn_qa_id" value="0">
		<input type="hidden" name="hdn_list_onegate_qa_id" value="">		
		<input type="hidden" name="hdn_status" value="<?php echo $v_status; ?>">
		<input type="hidden" name="hdn_top_id" value="<?php echo $v_top_id; ?>">
		<input type="hidden" name="hdn_bottom_id" value="<?php echo $v_bottom_id ;?>">
		<input type="hidden" name="hdn_fisrt" value="<?php echo $v_fisrt; ?>">
		<input type="hidden" name="hdn_last" value="<?php echo $v_last; ?>">
		<input type="hidden" name="hdn_direction" value="<?php echo $v_direction; ?>">
		<input type="hidden" name="hdn_exception_qa_id" value="<?php echo $v_exception_qa_id; ?>">
		<input type="hidden" name="hdn_cate_id" value="<?php echo $v_cate_id; ?>">
		<input type="hidden" name="hdn_cate" value="<?php echo $v_cate; ?>">
		<input type="hidden" name="hdn_agency" value="<?php echo $v_agency;?>">
		<input type="hidden" name="hdn_agency_id" value="<?php echo $v_agency_id;?>">
		<input type="hidden" name="hdn_qa_answerer_name" value="<?php echo $v_qa_answerer_name;?>">
		<input type="hidden" name="hdn_page" value="<?php echo $v_page;?>">
	<tr>

		<td class="normal_label"><?php echo CONST_CATE_LABEL;?></td>
		<td colspan="3">
			<select class="normal_selectbox" name="sel_cate" message = "<?php echo CONST_CATE_MESSAGE; ?>" style="width:90%" onChange="cbo_onchange(this,document.forms(0).hdn_cate_id);"><?php
			if (sizeof($arr_all_cate_for_staff)==0){?>
            <option id="" value="">----   <?php echo CONST_CATE_NAME_LABEL;?>  ----</option><?php
			}?>
            <?php echo _generate_select_option($arr_all_cate_for_staff,'0','0','2', $v_cate_id);?>
          </select>
		</td>
		<td style="display:none" colspan="3"class="normal_label"><?php echo CONST_AGENCY_NAME_LABEL;?></td>
		<td style="display:none">
			<select class="normal_selectbox" name="sel_agency" style="width:180" message = "<?php echo CONST_AGENCY_MESSAGE; ?>" onChange="cbo_onchange(this,document.forms(0).hdn_agency_id);">
            <option id="" value="">-----<?php echo CONST_AGENCY_NAME_LABEL;?>-----</option>
            	<?php echo _generate_select_option($arr_all_agency_for_staff,'1','0','2', $_ISA_OWNER_CODE);?>
          </select>
		</td>
	</tr>		
	<tr>
		<td class="normal_label">
			<?php echo CONST_QA_STATUS_LABEL;?>
		</td>
		<td>
			<select class="normal_selectbox" name="sel_status"  style="width:150 "onChange="cbo_onchange(this,document.forms(0).hdn_status);"><?php
				for ($i = 1; $i<= sizeof($arr_status); $i++){
					$v_checked = "";
					if ($v_status == $arr_status[$i]['id']){
						$v_checked = "selected";
					}?>
					<option id="<? echo $arr_status[$i]['id'];?>" value="<? echo $arr_status[$i]['id'];?>" <?php echo $v_checked;?>><? echo $arr_status[$i]['name'];?></option><?php
				}?>
			</select>
		</td>
		<td class="normal_label"><?php echo CONST_QA_QUESTION_FILTER_LABEL;?></td>
		<td >
			<input type="text" name="txt_filter" class="normal_textbox" value="<?php echo $v_filter; ?>" onKeyDown="txt_filter_keydown()">
			<input type="button" name="btn_filter" class="small_button" style="width:20%" value="<?php echo _CONST_FILTER_BUTTON; ?>" onClick="document.forms(0).hdn_page.value = 1;btn_filter_onclick(document.forms(0).hdn_filter,document.forms(0).txt_filter,'DISPLAY_ALL_VOTE_QUESTION')">
		</td>		
	</tr>
	<tr><td height="5"></td></tr>
</table>
<!-- Bat cac phim: F12=false; Insert=true; Delete=true, ESC=false; Enter=false -->
<div id="hotkey" onKeyDown="javascript:process_hot_key(false,true,true,false,false);">
<!--Bang bang hien thi tieu de danh sach cau hoi -->
<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">
	<col width="5%"><col width="50%"><col width="15%"><col width="15%"><col width="15%">
	<tr class="header">
		<td align="center">#</td>
		<td align="center"><?php echo CONST_QA_TITLE_LABEL; ?></td>
		<td align="center"><?php echo CONST_QA_SEND_DATE_LABEL; ?></td>
		<td align="center"><?php echo CONST_QA_ANSWER_DATE_LABEL; ?></td>
		<td align="center"><?php echo CONST_QA_STATUS_LABEL; ?></td>
	</tr>
</table>	
<!--Bang hien thi danh sach cau hoi dap-->
<div style="overflow: auto; width: 100%; height:<?php echo _CONST_HEIGHT_OF_LIST;?>;padding-left:0px;margin:0px">
<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">
	<col width="5%"><col width="50%"><col width="15%"><col width="15%"><col width="15%"><?php  
	if ($v_count >0){
		for($row_index = 0;$row_index< $v_count ;$row_index++){
			$v_qa_id = $arr_all_onegate_qa[$row_index]['PK_QA'];
			$v_qa_title = $arr_all_onegate_qa[$row_index]['C_QUESTION_TITLE'];
			$v_qa_sender_name = $arr_all_onegate_qa[$row_index]['C_QUESTIONER_NAME'];
			$v_answerer_id = $arr_all_onegate_qa[$row_index]['FK_ANSWERER'];
			$v_answerer_name = $arr_all_onegate_qa[$row_index]['C_ANSWERER_NAME'];
			/*
			if ($v_answerer_id>0){
				$v_answerer_name =  _get_item_attr_by_id($_SESSION['arr_all_staff'], $v_answerer_id, 'name');
			}else{
				$v_answerer_name =  _get_item_attr_by_id($_SESSION['arr_all_staff'], $_SESSION['staff_id'], 'name');
			}
			*/
			$v_qa_send_date = $arr_all_onegate_qa[$row_index]['C_QUESTION_DATE'];
			$v_qa_answer_date = $arr_all_onegate_qa[$row_index]['C_ANSWER_DATE'];
			$v_qa_answered_date = $arr_all_onegate_qa[$row_index]['C_ANSWER_DATE'];
			$v_qa_status = $arr_all_onegate_qa[$row_index]['C_STATUS'];					
			
			if ($v_qa_status == 0){
				$v_qa_status_name = CONST_QA_UNANSWER_STATUS_LABEL;}
			if ($v_qa_status == 1){
				$v_qa_status_name = CONST_QA_WAITING_STATUS_LABEL;}
			if ($v_qa_status == 2){
				$v_qa_status_name = CONST_QA_APPROVED_STATUS_LABEL;}
				
			$v_url = "row_onclick(" . "document.forms(0).hdn_qa_id"  . "," . $v_qa_id . "," . "'DISPLAY_SINGLE_QA_QUESTION','" . $v_goto_url . "')";
			if ($v_current_style_name == "odd_row"){
				$v_current_style_name = "round_row";
			}else{
				$v_current_style_name = "odd_row";
			}?>	
			<tr class="<?php echo $v_current_style_name ?>"> 
				<td align="center">
					<input type="checkbox" name="chk_qa_id" value="<?php echo $v_qa_id; ?>">
					<input type="hidden" name="hdn_status_id" value="<?php echo $v_qa_status; ?>">
				</td>	
				<td  align="left" onclick="<?php echo $v_url ;?>">
					<?php echo $v_qa_title; ?><a name="<?php echo $v_qa_id;?>">&nbsp;</a>
				</td>
				<td  align="center" onclick="<?php echo $v_url ;?>">
					<?php echo _yyyymmdd_to_ddmmyyyy($v_qa_send_date);?>&nbsp;
				</td>
				<td  align="center" onclick="<?php echo $v_url ;?>">
					<?php echo _yyyymmdd_to_ddmmyyyy($v_qa_answer_date);?>&nbsp;
				</td>
				<td  align="center" onclick="<?php echo $v_url ;?>">
					<?php echo $v_qa_status_name; ?>&nbsp;
				</td>
			</tr><?php 
		}
	}
	if ($v_current_style_name == "odd_row"){
		$v_next_style_name = "round_row";
	}else{
		$v_next_style_name = "odd_row";
	}
	echo _add_empty_row($v_count,10,$v_current_style_name,$v_next_style_name,5);
	?>
</table>
</div>
<!--Table chua phan trang va cac button-->
<table width="100%" align="center">
	<tr>
		<td align="left" class="normal_label"><small class="normal_starmark"><?php echo CONST_NUMBER_QA_LABEL."&nbsp;". $v_count ."&nbsp;" . CONST_NUMBER_QA_LABEL2;?></small></td>
		<td align="right" class="normal_link"><? 
			if ($v_total_qa >0){
				echo PageBreak($v_total_qa,$v_page,10,_CONST_NUMBER_OF_ROW_PER_LIST);	
			}?>
		</td>
	</tr>
	<tr><td height="10"></td></tr>
	<tr>
		<td align="center" colspan="5"><?php 
			if ($v_is_granted_qa_question_approve) { ?>
				<input type="button" value="<?php echo _CONST_APPROVE_BUTTON; ?>" name="btn_approve" class="normal_button" onClick="btn_approve_onclick(document.forms(0).chk_qa_id,document.forms(0).hdn_status_id,document.forms(0).hdn_qa_id,'DISPLAY_SINGLE_QA_QUESTION_FOR_APPROVE');"><?php
			} if ($v_is_granted_qa_question_delete){ ?>
				<input type="button" value="<?php echo _CONST_DELETE_BUTTON; ?>" name="btn_delete" class="normal_button" onClick="btn_delete_onclick(document.forms(0).chk_qa_id,document.forms(0).hdn_list_onegate_qa_id,'DELETE_QA_QUESTION')"><?php
			} ?>
		</td>
	</tr>
</table>
</div id="hotkey">
</form> 
<script>
	document.all.goto.href="#<? echo $v_current_item_id;?>";
	document.all.goto.click();
</script>
	
